﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Xml;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;
using YJKGeometryFuncs;
using YJKRevitRoom.NumberRoomControler;
using YJKRevitRoom.NumberRooms;
using YJKRevitRoom.NumberRoomSetting;

namespace YJKRevitRoom.PublicForm
{
	public partial class DlgRoomNumber : System.Windows.Forms.Form
	{
		public bool PickButton
		{
			get
			{
				return this.m_PickButton;
			}
			set
			{
				this.m_PickButton = value;
			}
		}

		public int CurContinueNum
		{
			get
			{
				int result = 1;
				if (this.tabControl1.SelectedIndex == 0)
				{
					result = Convert.ToInt32(this.tbRRNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 1)
				{
					result = Convert.ToInt32(this.tbORNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 2)
				{
					result = Convert.ToInt32(this.tbBRNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 3)
				{
					result = Convert.ToInt32(this.tbCRNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 4)
				{
					result = Convert.ToInt32(this.tbZRNum.Text);
				}
				return result;
			}
			set
			{
				if (this.tabControl1.SelectedIndex == 0)
				{
					this.tbRRNum.Text = value.ToString();
					return;
				}
				if (this.tabControl1.SelectedIndex == 1)
				{
					this.tbORNum.Text = value.ToString();
					return;
				}
				if (this.tabControl1.SelectedIndex == 2)
				{
					this.tbBRNum.Text = value.ToString();
					return;
				}
				if (this.tabControl1.SelectedIndex == 3)
				{
					this.tbCRNum.Text = value.ToString();
					return;
				}
				if (this.tabControl1.SelectedIndex == 4)
				{
					this.tbZRNum.Text = value.ToString();
				}
			}
		}

		public DlgRoomNumber.OperateType CurrentOperateType
		{
			get
			{
				return this.m_CurrentOperateType;
			}
		}

		public bool RoomNumberValidating()
		{
			try
			{
				if (this.tabControl1.SelectedIndex == 0)
				{
					Convert.ToInt32(this.tbRRNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 1)
				{
					Convert.ToInt32(this.tbORNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 2)
				{
					Convert.ToInt32(this.tbBRNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 3)
				{
					Convert.ToInt32(this.tbCRNum.Text);
				}
				else if (this.tabControl1.SelectedIndex == 4)
				{
					Convert.ToInt32(this.tbZRNum.Text);
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("房间编号不能为空");
				return false;
			}
			try
			{
				if (this.tabControl1.SelectedIndex == 0)
				{
					Convert.ToDouble(this.tbRACoefficient.Text);
				}
				else if (this.tabControl1.SelectedIndex == 1)
				{
					Convert.ToDouble(this.tbOACoefficient.Text);
				}
				else if (this.tabControl1.SelectedIndex == 2)
				{
					Convert.ToDouble(this.tbBACoefficient.Text);
				}
				else if (this.tabControl1.SelectedIndex == 3)
				{
					Convert.ToDouble(this.tbCACoefficient.Text);
				}
				else if (this.tabControl1.SelectedIndex == 4)
				{
					Convert.ToDouble(this.tbZACoefficient.Text);
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("面积系数不能为空");
				return false;
			}
			return true;
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void DlgRoomNumber_MouseLeave(object sender, EventArgs e)
		{
			if (!this.GetDimStrings())
			{
				return;
			}
			if (!base.ClientRectangle.Contains(base.PointToClient(Cursor.Position)))
			{
				this.SendSetfocusMessage();
				return;
			}
			base.Focus();
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void DlgRoomNumber_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SimulationPressESC();
		}

		private void SimulationPressESC()
		{
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			DlgRoomNumber.keybd_event((byte)bVk, 0, dwFlags, 0);
			DlgRoomNumber.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		private void SendSetfocusMessage()
		{
			int wMsg = 7;
			DlgRoomNumber.SendMessage(CmdNumberRooms._hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
		}

		protected override void DefWndProc(ref Message m)
		{
			int msg = m.Msg;
			if (msg == 1281)
			{
				if (this.CurrentOperateType == DlgRoomNumber.OperateType.OT_Pick)
				{
					this.NumberStep();
					return;
				}
			}
			else
			{
				base.DefWndProc(ref m);
			}
		}

		private void NumberStep()
		{
			if (this.tabControl1.SelectedIndex == 0)
			{
				int num = Convert.ToInt32(this.tbRRNum.Text);
				num++;
				this.tbRRNum.Text = num.ToString();
				return;
			}
			if (this.tabControl1.SelectedIndex == 1)
			{
				int num2 = Convert.ToInt32(this.tbORNum.Text);
				num2++;
				this.tbORNum.Text = num2.ToString();
				return;
			}
			if (this.tabControl1.SelectedIndex == 2)
			{
				int num3 = Convert.ToInt32(this.tbBRNum.Text);
				num3++;
				this.tbBRNum.Text = num3.ToString();
				return;
			}
			if (this.tabControl1.SelectedIndex == 3)
			{
				int num4 = Convert.ToInt32(this.tbCRNum.Text);
				num4++;
				this.tbCRNum.Text = num4.ToString();
				return;
			}
			if (this.tabControl1.SelectedIndex == 4)
			{
				int num5 = Convert.ToInt32(this.tbZRNum.Text);
				num5++;
				this.tbZRNum.Text = num5.ToString();
			}
		}

		public DlgRoomNumber()
		{
			this.InitializeComponent();
			this.cmbODensity.Text = "人员密度（人/㎡）";
			this.cmbBDensity.Text = "人员密度（人/㎡）";
			this.cmbCDensity.Text = "人员密度（人/㎡）";
			this.cmbOtherDensity.Text = "人员密度（人/㎡）";
		}

		public DlgRoomNumber(ExternalCommandData cmdData)
		{
			this.InitializeComponent();
			this.m_Revit = cmdData;
			this.cmbODensity.Text = "人员密度（人/㎡）";
			this.cmbBDensity.Text = "人员密度（人/㎡）";
			this.cmbCDensity.Text = "人员密度（人/㎡）";
			this.cmbOtherDensity.Text = "人员密度（人/㎡）";
			this.InitialDensityData();
			this.GetSortFloorLevel();
		}

		public bool GetDimStrings()
		{
			try
			{
				this.bnForShareParameter = new ButtonNode();
				if (this.tabControl1.SelectedIndex == 0)
				{
					this.bnForShareParameter.sDName = this.GetChineseRoomName(this.tbRDName.Text);
					this.bnForShareParameter.sEngName = this.GetEnglishRoomName(this.tbRDName.Text);
					this.bnForShareParameter.nRoomNumber = Convert.ToInt32(this.tbRRNum.Text);
					this.bnForShareParameter.sApartName = this.tbRApartName.Text;
					this.bnForShareParameter.sApartNumber = this.tbRApartNum.Text;
					this.bnForShareParameter.sUnit = this.tbRUnit.Text;
					this.bnForShareParameter.dAreaCoefficient = Convert.ToDouble(this.tbRACoefficient.Text);
					this.bnForShareParameter.sBuildingNumber = this.tbRBuildingNum.Text;
					this.bnForShareParameter.strPopDensity = "";
					this.bnForShareParameter.bDrawApart = true;
				}
				else if (this.tabControl1.SelectedIndex == 1)
				{
					this.bnForShareParameter.sDName = this.GetChineseRoomName(this.tbODName.Text);
					this.bnForShareParameter.sEngName = this.GetEnglishRoomName(this.tbODName.Text);
					this.bnForShareParameter.nRoomNumber = Convert.ToInt32(this.tbORNum.Text);
					this.bnForShareParameter.sApartName = " ";
					this.bnForShareParameter.sApartNumber = " ";
					this.bnForShareParameter.sUnit = " ";
					this.bnForShareParameter.dAreaCoefficient = Convert.ToDouble(this.tbOACoefficient.Text);
					this.bnForShareParameter.sBuildingNumber = this.tbOBuildingNum.Text;
					this.bnForShareParameter.strPopDensity = this.GetPopulationDensity();
					this.bnForShareParameter.bDrawApart = false;
				}
				else if (this.tabControl1.SelectedIndex == 2)
				{
					this.bnForShareParameter.sDName = this.GetChineseRoomName(this.tbBDName.Text);
					this.bnForShareParameter.sEngName = this.GetEnglishRoomName(this.tbBDName.Text);
					this.bnForShareParameter.nRoomNumber = Convert.ToInt32(this.tbBRNum.Text);
					this.bnForShareParameter.sApartName = "";
					this.bnForShareParameter.sApartNumber = "";
					this.bnForShareParameter.sUnit = "";
					this.bnForShareParameter.dAreaCoefficient = Convert.ToDouble(this.tbBACoefficient.Text);
					this.bnForShareParameter.sBuildingNumber = this.tbBBuildingNum.Text;
					this.bnForShareParameter.strPopDensity = this.GetPopulationDensity();
					this.bnForShareParameter.bDrawApart = false;
				}
				else if (this.tabControl1.SelectedIndex == 3)
				{
					this.bnForShareParameter.sDName = this.GetChineseRoomName(this.tbCDName.Text);
					this.bnForShareParameter.sEngName = this.GetEnglishRoomName(this.tbCDName.Text);
					this.bnForShareParameter.nRoomNumber = Convert.ToInt32(this.tbCRNum.Text);
					this.bnForShareParameter.sApartName = "";
					this.bnForShareParameter.sApartNumber = "";
					this.bnForShareParameter.sUnit = "";
					this.bnForShareParameter.dAreaCoefficient = Convert.ToDouble(this.tbCACoefficient.Text);
					this.bnForShareParameter.sBuildingNumber = this.tbCBuildingNum.Text;
					this.bnForShareParameter.strPopDensity = this.GetPopulationDensity();
					this.bnForShareParameter.bDrawApart = false;
				}
				else if (this.tabControl1.SelectedIndex == 4)
				{
					this.bnForShareParameter.sDName = this.GetChineseRoomName(this.tbZDName.Text);
					this.bnForShareParameter.sEngName = this.GetEnglishRoomName(this.tbZDName.Text);
					this.bnForShareParameter.nRoomNumber = Convert.ToInt32(this.tbZRNum.Text);
					this.bnForShareParameter.sApartName = this.tbZApartName.Text;
					this.bnForShareParameter.sApartNumber = this.tbZApartNum.Text;
					this.bnForShareParameter.sUnit = this.tbZUnit.Text;
					this.bnForShareParameter.dAreaCoefficient = Convert.ToDouble(this.tbZACoefficient.Text);
					this.bnForShareParameter.sBuildingNumber = this.tbZBuildingNum.Text;
					this.bnForShareParameter.strPopDensity = this.GetPopulationDensity();
					this.bnForShareParameter.bDrawApart = true;
				}
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private void DlgRoomNumber_Load(object sender, EventArgs e)
		{
			string text = Product.UserDataLocation + "\\RoomNumber.xml";
			if (!File.Exists(text))
			{
				text = Product.InstallLocation + "\\Data\\RoomNumber.xml";
			}
			string text2 = "";
			this.ReadDataFromXML(text, ref text2);
			this.ReloadDialogData(text, ref text2);
			this.CreateResidenceButtons();
		}

		private void DlgRoomNumber_FormClosing(object sender, FormClosingEventArgs e)
		{
			string fileName = Product.UserDataLocation + "\\RoomNumber.xml";
			this.WriteModuleXMLFile(fileName);
		}

		private void CreateResidenceButtons()
		{
			double num = 1.5;
			double num2 = 1.5;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			int num3 = 0;
			for (int i = 0; i < 12; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					RadioButton radioButton = new RadioButton();
					radioButton.Appearance = Appearance.Button;
					radioButton.TextAlign = ContentAlignment.MiddleCenter;
					radioButton.Location = new System.Drawing.Point((int)(10.0 * num + (double)(j * 85) * num), (int)(20.0 + (double)(i * 30) * num));
					radioButton.Size = new Size((int)(80.0 * num), (int)(25.0 * num));
					radioButton.Text = this.arBNResidence.ElementAt(num3).sDName;
					radioButton.Tag = num3;
					radioButton.Click += this.btnResidence_Click;
					this.gbResidence.Controls.Add(radioButton);
					if (num3 == this.nResidenceIndex)
					{
						this.btnSelectedResidence = radioButton;
						this.btnSelectedResidence.Checked = true;
					}
					num3++;
				}
			}
			this.tbRDName.Text = this.arBNResidence.ElementAt(this.nResidenceIndex).sDName;
			this.tbRACoefficient.Text = this.arBNResidence.ElementAt(this.nResidenceIndex).dAreaCoefficient.ToString();
			this.bCreatedResidence = true;
		}

		private void CreateOfficeButtons()
		{
			double num = 1.0;
			double num2 = 1.0;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			int num3 = 0;
			for (int i = 0; i < 14; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					RadioButton radioButton = new RadioButton();
					radioButton.Appearance = Appearance.Button;
					radioButton.TextAlign = ContentAlignment.MiddleCenter;
					radioButton.Location = new System.Drawing.Point((int)(10.0 * num + (double)(j * 85) * num), (int)(15.0 + (double)(i * 30) * num));
					radioButton.Size = new Size((int)(80.0 * num), (int)(25.0 * num));
					radioButton.Text = this.arBNOffice.ElementAt(num3).sDName;
					radioButton.Tag = num3;
					radioButton.Click += this.btnOffice_Click;
					this.gbOffice.Controls.Add(radioButton);
					if (num3 == this.nOfficeIndex)
					{
						this.btnSelectedOffice = radioButton;
						this.btnSelectedOffice.Checked = true;
					}
					num3++;
				}
			}
			this.tbODName.Text = this.arBNOffice.ElementAt(this.nOfficeIndex).sDName;
			this.tbOACoefficient.Text = this.arBNOffice.ElementAt(this.nOfficeIndex).dAreaCoefficient.ToString();
			this.bCreatedOffice = true;
			this.UpdatePopulationDensity();
		}

		private void CreateBusinessButtons()
		{
			double num = 1.0;
			double num2 = 1.0;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			int num3 = 0;
			for (int i = 0; i < 14; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					RadioButton radioButton = new RadioButton();
					radioButton.Appearance = Appearance.Button;
					radioButton.TextAlign = ContentAlignment.MiddleCenter;
					radioButton.Location = new System.Drawing.Point((int)(10.0 * num + (double)(j * 85) * num), (int)(15.0 + (double)(i * 30) * num));
					radioButton.Size = new Size((int)(80.0 * num), (int)(25.0 * num));
					radioButton.Text = this.arBNBusiness.ElementAt(num3).sDName;
					radioButton.Tag = num3;
					radioButton.Click += this.btnBusiness_Click;
					this.gbBusiness.Controls.Add(radioButton);
					if (num3 == this.nBusinessIndex)
					{
						this.btnSelectedBusiness = radioButton;
						this.btnSelectedBusiness.Checked = true;
					}
					num3++;
				}
			}
			this.tbBDName.Text = this.arBNBusiness.ElementAt(this.nBusinessIndex).sDName;
			this.tbBACoefficient.Text = this.arBNBusiness.ElementAt(this.nBusinessIndex).dAreaCoefficient.ToString();
			this.bCreatedBusiness = true;
			this.UpdatePopulationDensity();
		}

		private void CreateCateringButtons()
		{
			double num = 1.0;
			double num2 = 1.0;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			int num3 = 0;
			for (int i = 0; i < 12; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					RadioButton radioButton = new RadioButton();
					radioButton.Appearance = Appearance.Button;
					radioButton.TextAlign = ContentAlignment.MiddleCenter;
					radioButton.Location = new System.Drawing.Point((int)(10.0 * num + (double)(j * 85) * num), (int)(15.0 + (double)(i * 30) * num));
					radioButton.Size = new Size((int)(80.0 * num), (int)(25.0 * num));
					radioButton.Text = this.arBNCatering.ElementAt(num3).sDName;
					radioButton.Tag = num3;
					radioButton.Click += this.btnCatering_Click;
					this.gbCatering.Controls.Add(radioButton);
					if (num3 == this.nCateringIndex)
					{
						this.btnSelectedCatering = radioButton;
						this.btnSelectedCatering.Checked = true;
					}
					num3++;
				}
			}
			this.tbCDName.Text = this.arBNCatering.ElementAt(this.nCateringIndex).sDName;
			this.tbCACoefficient.Text = this.arBNCatering.ElementAt(this.nCateringIndex).dAreaCoefficient.ToString();
			this.bCreatedCatering = true;
			this.UpdatePopulationDensity();
		}

		private void CreateCustomButtons()
		{
			foreach (ButtonNode buttonNode in this.arBNCustom)
			{
				this.AddDBGRow(this.dbgHall, buttonNode.sDName, buttonNode.dAreaCoefficient, false);
			}
			DataGridViewRow dataGridViewRow = this.dbgHall.SelectedRows[0];
			this.tbZDName.Text = dataGridViewRow.Cells[0].Value.ToString();
			this.tbZACoefficient.Text = dataGridViewRow.Cells[1].Value.ToString();
			this.tbZDName.Focus();
			this.tbZDName.SelectAll();
			this.bCreatedCustom = true;
			this.UpdatePopulationDensity();
		}

		private void btnResidence_Click(object sender, EventArgs e)
		{
			this.btnSelectedResidence = (sender as RadioButton);
			this.nResidenceIndex = Convert.ToInt32(this.btnSelectedResidence.Tag);
			ButtonNode buttonNode = this.arBNResidence.ElementAt(this.nResidenceIndex);
			this.tbRDName.Text = buttonNode.sDName;
			this.tbRACoefficient.Text = buttonNode.dAreaCoefficient.ToString();
			this.tbRDName.Focus();
			this.tbRDName.SelectAll();
		}

		private void btnOffice_Click(object sender, EventArgs e)
		{
			this.btnSelectedOffice = (sender as RadioButton);
			this.nOfficeIndex = Convert.ToInt32(this.btnSelectedOffice.Tag);
			ButtonNode buttonNode = this.arBNOffice.ElementAt(this.nOfficeIndex);
			this.tbODName.Text = buttonNode.sDName;
			this.tbOACoefficient.Text = buttonNode.dAreaCoefficient.ToString();
			this.tbODName.Focus();
			this.tbODName.SelectAll();
			this.UpdatePopulationDensity();
		}

		private void btnBusiness_Click(object sender, EventArgs e)
		{
			this.btnSelectedBusiness = (sender as RadioButton);
			this.nBusinessIndex = Convert.ToInt32(this.btnSelectedBusiness.Tag);
			ButtonNode buttonNode = this.arBNBusiness.ElementAt(this.nBusinessIndex);
			this.tbBDName.Text = buttonNode.sDName;
			this.tbBACoefficient.Text = buttonNode.dAreaCoefficient.ToString();
			this.tbBDName.Focus();
			this.tbBDName.SelectAll();
			this.UpdatePopulationDensity();
		}

		private void btnCatering_Click(object sender, EventArgs e)
		{
			this.btnSelectedCatering = (sender as RadioButton);
			this.nCateringIndex = Convert.ToInt32(this.btnSelectedCatering.Tag);
			ButtonNode buttonNode = this.arBNCatering.ElementAt(this.nCateringIndex);
			this.tbCDName.Text = buttonNode.sDName;
			this.tbCACoefficient.Text = buttonNode.dAreaCoefficient.ToString();
			this.tbCDName.Focus();
			this.tbCDName.SelectAll();
			this.UpdatePopulationDensity();
		}

		private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.tabControl1.SelectedIndex == 0)
			{
				if (!this.bCreatedResidence)
				{
					this.CreateResidenceButtons();
				}
				this.btnChange.Visible = true;
				return;
			}
			if (this.tabControl1.SelectedIndex == 1)
			{
				if (!this.bCreatedOffice)
				{
					this.CreateOfficeButtons();
				}
				this.btnChange.Visible = false;
				return;
			}
			if (this.tabControl1.SelectedIndex == 2)
			{
				if (!this.bCreatedBusiness)
				{
					this.CreateBusinessButtons();
				}
				this.btnChange.Visible = false;
				return;
			}
			if (this.tabControl1.SelectedIndex == 3)
			{
				if (!this.bCreatedCatering)
				{
					this.CreateCateringButtons();
				}
				this.btnChange.Visible = false;
				return;
			}
			if (this.tabControl1.SelectedIndex == 4)
			{
				if (!this.bCreatedCustom)
				{
					this.CreateCustomButtons();
				}
				this.btnChange.Visible = true;
			}
		}

		private void tbRDName_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedResidence != null)
			{
				this.btnSelectedResidence.Text = this.tbRDName.Text;
				this.arBNResidence[this.nResidenceIndex].sDName = this.tbRDName.Text;
			}
		}

		private void tbRACoefficient_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedResidence != null)
			{
				this.arBNResidence[this.nResidenceIndex].dAreaCoefficient = Convert.ToDouble(this.tbRACoefficient.Text);
			}
		}

		private void tbOACoefficient_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedOffice != null)
			{
				this.arBNOffice[this.nOfficeIndex].dAreaCoefficient = Convert.ToDouble(this.tbOACoefficient.Text);
			}
		}

		private void tbBACoefficient_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedBusiness != null)
			{
				this.arBNBusiness[this.nBusinessIndex].dAreaCoefficient = Convert.ToDouble(this.tbBACoefficient.Text);
			}
		}

		private void tbCACoefficient_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedResidence != null)
			{
				this.arBNCatering[this.nCateringIndex].dAreaCoefficient = Convert.ToDouble(this.tbCACoefficient.Text);
			}
		}

		private void tbODName_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedOffice != null)
			{
				this.btnSelectedOffice.Text = this.tbODName.Text;
				this.arBNOffice[this.nOfficeIndex].sDName = this.tbODName.Text;
				this.UpdatePopulationDensity();
			}
		}

		private void tbORNum_TextChanged(object sender, EventArgs e)
		{
		}

		private void tbBDName_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedOffice != null)
			{
				this.btnSelectedBusiness.Text = this.tbBDName.Text;
				this.arBNBusiness[this.nBusinessIndex].sDName = this.tbBDName.Text;
				this.UpdatePopulationDensity();
			}
		}

		private void tbBRNum_TextChanged(object sender, EventArgs e)
		{
		}

		private void tbCDName_TextChanged(object sender, EventArgs e)
		{
			if (this.btnSelectedCatering != null)
			{
				this.btnSelectedCatering.Text = this.tbCDName.Text;
				this.arBNCatering[this.nCateringIndex].sDName = this.tbCDName.Text;
				this.UpdatePopulationDensity();
			}
		}

		private void tbCRNum_TextChanged(object sender, EventArgs e)
		{
		}

		public bool ReadDataFromXML(string xmlFilePath, ref string errMessage)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(xmlFilePath);
			XmlNode xmlNode = xmlDocument.SelectSingleNode(this.RootNodeName);
			if (xmlNode == null)
			{
				errMessage = "文件格式不符！";
				return false;
			}
			XmlNode xmlNode2 = xmlNode.SelectSingleNode(this.ResidenceNodeName);
			if (xmlNode2 == null)
			{
				errMessage = "文件中缺少数据！";
				return false;
			}
			if (!this.DoReadInfo(0, xmlNode2, ref errMessage))
			{
				return false;
			}
			XmlNode xmlNode3 = xmlNode.SelectSingleNode(this.OfficeNodeName);
			if (xmlNode3 == null)
			{
				errMessage = "文件中缺少数据！";
				return false;
			}
			if (!this.DoReadInfo(1, xmlNode3, ref errMessage))
			{
				return false;
			}
			XmlNode xmlNode4 = xmlNode.SelectSingleNode(this.BusinessNodeName);
			if (xmlNode4 == null)
			{
				errMessage = "文件中缺少数据！";
				return false;
			}
			if (!this.DoReadInfo(2, xmlNode4, ref errMessage))
			{
				return false;
			}
			XmlNode xmlNode5 = xmlNode.SelectSingleNode(this.CateringNodeName);
			if (xmlNode5 == null)
			{
				errMessage = "文件中缺少数据！";
				return false;
			}
			if (!this.DoReadInfo(3, xmlNode5, ref errMessage))
			{
				return false;
			}
			XmlNode xmlNode6 = xmlNode.SelectSingleNode(this.CustomNodeName);
			if (xmlNode6 == null)
			{
				errMessage = "文件中缺少数据！";
				return false;
			}
			return this.DoReadInfo(4, xmlNode6, ref errMessage);
		}

		private bool DoReadInfo(int type, XmlNode xnNode, ref string errMessage)
		{
			foreach (object obj in xnNode.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				XmlElement xmlElement = (XmlElement)xmlNode;
				string innerText = xmlNode.SelectSingleNode("标注名称").InnerText;
				double dAreaCoefficient = Convert.ToDouble(xmlNode.SelectSingleNode("面积系数").InnerText);
				ButtonNode buttonNode = new ButtonNode();
				buttonNode.sDName = innerText;
				buttonNode.dAreaCoefficient = dAreaCoefficient;
				if (type == 0)
				{
					this.arBNResidence.Add(buttonNode);
				}
				else if (type == 1)
				{
					this.arBNOffice.Add(buttonNode);
				}
				else if (type == 2)
				{
					this.arBNBusiness.Add(buttonNode);
				}
				else if (type == 3)
				{
					this.arBNCatering.Add(buttonNode);
				}
				else if (type == 4)
				{
					this.arBNCustom.Add(buttonNode);
				}
			}
			return true;
		}

		public bool ReloadDialogData(string xmlFilePath, ref string errMessage)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(xmlFilePath);
			XmlNode xmlNode = xmlDocument.SelectSingleNode(this.RootNodeName);
			if (xmlNode == null)
			{
				errMessage = "文件格式不符！";
				return false;
			}
			XmlNode xmlNode2 = xmlNode.SelectSingleNode("DialogData");
			if (xmlNode2 == null)
			{
				errMessage = "文件中缺少数据！";
				return false;
			}
			foreach (object obj in xmlNode2.ChildNodes)
			{
				XmlNode xmlNode3 = (XmlNode)obj;
				XmlNode xmlNode4 = xmlNode3.SelectSingleNode("选择页");
				int num = Convert.ToInt32(xmlNode4.InnerText);
				if (num == 0)
				{
					xmlNode4 = xmlNode3.SelectSingleNode("按钮索引");
					this.nResidenceIndex = Convert.ToInt32(xmlNode4.InnerText);
					xmlNode4 = xmlNode3.SelectSingleNode("标注名称");
					this.tbRDName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("房间编号");
					this.tbRRNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("面积系数");
					this.tbRACoefficient.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("户型名称");
					this.tbRApartName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("户型编号");
					this.tbRApartNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("单元");
					this.tbRUnit.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("楼号");
					this.tbRBuildingNum.Text = xmlNode4.InnerText;
				}
				else if (num == 1)
				{
					xmlNode4 = xmlNode3.SelectSingleNode("按钮索引");
					this.nOfficeIndex = Convert.ToInt32(xmlNode4.InnerText);
					xmlNode4 = xmlNode3.SelectSingleNode("标注名称");
					this.tbODName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("房间编号");
					this.tbORNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("面积系数");
					this.tbOACoefficient.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("楼号");
					this.tbOBuildingNum.Text = xmlNode4.InnerText;
				}
				else if (num == 2)
				{
					xmlNode4 = xmlNode3.SelectSingleNode("按钮索引");
					this.nBusinessIndex = Convert.ToInt32(xmlNode4.InnerText);
					xmlNode4 = xmlNode3.SelectSingleNode("标注名称");
					this.tbBDName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("房间编号");
					this.tbBRNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("面积系数");
					this.tbBACoefficient.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("楼号");
					this.tbBBuildingNum.Text = xmlNode4.InnerText;
				}
				else if (num == 3)
				{
					xmlNode4 = xmlNode3.SelectSingleNode("按钮索引");
					this.nCateringIndex = Convert.ToInt32(xmlNode4.InnerText);
					xmlNode4 = xmlNode3.SelectSingleNode("标注名称");
					this.tbCDName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("房间编号");
					this.tbCRNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("面积系数");
					this.tbCACoefficient.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("楼号");
					this.tbCBuildingNum.Text = xmlNode4.InnerText;
				}
				else if (num == 4)
				{
					this.tabControl1.SelectedIndex = num;
					xmlNode4 = xmlNode3.SelectSingleNode("按钮索引");
					int num2 = Convert.ToInt32(xmlNode4.InnerText);
					if (this.dbgHall.Rows.Count > num2)
					{
						this.dbgHall.Rows[num2].Selected = true;
					}
					xmlNode4 = xmlNode3.SelectSingleNode("标注名称");
					this.tbZDName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("房间编号");
					this.tbZRNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("面积系数");
					this.tbZACoefficient.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("户型名称");
					this.tbZApartName.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("户型编号");
					this.tbZApartNum.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("单元");
					this.tbZUnit.Text = xmlNode4.InnerText;
					xmlNode4 = xmlNode3.SelectSingleNode("楼号");
					this.tbZBuildingNum.Text = xmlNode4.InnerText;
				}
				this.tabControl1.SelectedIndex = num;
			}
			return true;
		}

		private void WriteModuleXMLFile(string fileName)
		{
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				bool bExistXml;
				if (File.Exists(fileName))
				{
					xmlDocument.Load(fileName);
					bExistXml = true;
				}
				else
				{
					XmlNode newChild = xmlDocument.CreateXmlDeclaration("1.0", "gb2312", null);
					xmlDocument.AppendChild(newChild);
					XmlElement newChild2 = xmlDocument.CreateElement(this.RootNodeName);
					xmlDocument.AppendChild(newChild2);
					bExistXml = false;
				}
				this.ExportInfos(this.arBNResidence, this.ResidenceNodeName, xmlDocument, bExistXml);
				this.ExportInfos(this.arBNOffice, this.OfficeNodeName, xmlDocument, bExistXml);
				this.ExportInfos(this.arBNBusiness, this.BusinessNodeName, xmlDocument, bExistXml);
				this.ExportInfos(this.arBNCatering, this.CateringNodeName, xmlDocument, bExistXml);
				this.GetCustomDatas();
				this.ExportInfos(this.arBNCustom, this.CustomNodeName, xmlDocument, bExistXml);
				this.ExportDialogData("DialogData", xmlDocument, bExistXml);
				xmlDocument.Save(fileName);
			}
			catch (Exception)
			{
			}
		}

		private void ExportInfos(List<ButtonNode> arButtonNode, string dataNodeName, XmlDocument xmlDoc, bool bExistXml)
		{
			XmlNode xmlNode = xmlDoc.SelectSingleNode(this.RootNodeName);
			if (bExistXml)
			{
				XmlNode xmlNode2 = xmlNode.SelectSingleNode(dataNodeName);
				if (xmlNode2 != null)
				{
					xmlNode2.RemoveAll();
					xmlNode.RemoveChild(xmlNode2);
				}
			}
			XmlElement newChild = xmlDoc.CreateElement(dataNodeName);
			xmlNode.AppendChild(newChild);
			XmlNode xmlNode3 = xmlNode.SelectSingleNode(dataNodeName);
			int num = 1;
			foreach (ButtonNode buttonNode in arButtonNode)
			{
				string text = "按钮" + num.ToString();
				XmlElement newChild2 = xmlDoc.CreateElement(text);
				xmlNode3.AppendChild(newChild2);
				XmlNode xmlNode4 = xmlNode3.SelectSingleNode(text);
				XmlElement xmlElement = xmlDoc.CreateElement("标注名称");
				xmlElement.InnerText = buttonNode.sDName;
				xmlNode4.AppendChild(xmlElement);
				XmlNode xmlNode5 = xmlNode3.SelectSingleNode(text);
				xmlElement = xmlDoc.CreateElement("面积系数");
				xmlElement.InnerText = buttonNode.dAreaCoefficient.ToString();
				xmlNode5.AppendChild(xmlElement);
				num++;
			}
		}

		private void ExportDialogData(string dataNodeName, XmlDocument xmlDoc, bool bExistXml)
		{
			int num = 0;
			this.GetDimStrings();
			if (this.tabControl1.SelectedIndex == 0)
			{
				num = this.nResidenceIndex;
			}
			else if (this.tabControl1.SelectedIndex == 1)
			{
				num = this.nOfficeIndex;
			}
			else if (this.tabControl1.SelectedIndex == 2)
			{
				num = this.nBusinessIndex;
			}
			else if (this.tabControl1.SelectedIndex == 3)
			{
				num = this.nCateringIndex;
			}
			else if (this.tabControl1.SelectedIndex == 4)
			{
				num = this.dbgHall.SelectedRows[0].Index;
			}
			XmlNode xmlNode = xmlDoc.SelectSingleNode(this.RootNodeName);
			if (bExistXml)
			{
				XmlNode xmlNode2 = xmlNode.SelectSingleNode(dataNodeName);
				if (xmlNode2 != null)
				{
					xmlNode2.RemoveAll();
					xmlNode.RemoveChild(xmlNode2);
				}
			}
			XmlElement newChild = xmlDoc.CreateElement(dataNodeName);
			xmlNode.AppendChild(newChild);
			XmlNode xmlNode3 = xmlNode.SelectSingleNode(dataNodeName);
			string text = "界面按钮";
			XmlElement newChild2 = xmlDoc.CreateElement(text);
			xmlNode3.AppendChild(newChild2);
			XmlNode xmlNode4 = xmlNode3.SelectSingleNode(text);
			XmlElement xmlElement = xmlDoc.CreateElement("选择页");
			xmlElement.InnerText = this.tabControl1.SelectedIndex.ToString();
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("按钮索引");
			xmlElement.InnerText = num.ToString();
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("标注名称");
			xmlElement.InnerText = this.bnForShareParameter.sDName;
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("房间编号");
			xmlElement.InnerText = this.bnForShareParameter.nRoomNumber.ToString();
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("面积系数");
			xmlElement.InnerText = this.bnForShareParameter.dAreaCoefficient.ToString();
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("户型名称");
			xmlElement.InnerText = this.bnForShareParameter.sApartName;
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("户型编号");
			xmlElement.InnerText = this.bnForShareParameter.sApartNumber;
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("单元");
			xmlElement.InnerText = this.bnForShareParameter.sUnit;
			xmlNode4.AppendChild(xmlElement);
			xmlElement = xmlDoc.CreateElement("楼号");
			xmlElement.InnerText = this.bnForShareParameter.sBuildingNumber;
			xmlNode4.AppendChild(xmlElement);
		}

		private void GetCustomDatas()
		{
			if (this.dbgHall.Rows.Count > 0)
			{
				this.arBNCustom.Clear();
				foreach (object obj in ((IEnumerable)this.dbgHall.Rows))
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					string sDName = dataGridViewRow.Cells[0].Value.ToString();
					double dAreaCoefficient = Convert.ToDouble(dataGridViewRow.Cells[1].Value.ToString());
					ButtonNode buttonNode = new ButtonNode();
					buttonNode.sDName = sDName;
					buttonNode.dAreaCoefficient = dAreaCoefficient;
					this.arBNCustom.Add(buttonNode);
				}
			}
		}

		private void btnRect_Click(object sender, EventArgs e)
		{
			this.m_CurrentOperateType = DlgRoomNumber.OperateType.OT_Continue;
			this.m_PickButton = true;
			this.ChangeOperateState();
		}

		private void btnPick_Click(object sender, EventArgs e)
		{
			this.m_CurrentOperateType = DlgRoomNumber.OperateType.OT_Pick;
			this.m_PickButton = true;
			this.ChangeOperateState();
		}

		private void btnChange_Click(object sender, EventArgs e)
		{
			this.m_CurrentOperateType = DlgRoomNumber.OperateType.OT_Change;
			this.m_PickButton = true;
			this.ChangeOperateState();
		}

		private void ChangeOperateState()
		{
			Cursor.Position = new System.Drawing.Point(Cursor.Position.X, base.Bottom + 1);
			this.SendSetfocusMessage();
			this.SimulationPressESC();
		}

		private void btnAddName_Click(object sender, EventArgs e)
		{
			if (this.tbNewName.Text.Trim().CompareTo("") == 0)
			{
				return;
			}
			IEnumerator enumerator = ((IEnumerable)this.dbgHall.Rows).GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					if (((DataGridViewRow)enumerator.Current).Cells[0].Value.ToString().CompareTo(this.tbNewName.Text) == 0)
					{
						YJKMessageBox.Show("新名称在列表中已经存在，无法重复添加");
						return;
					}
				}
			}
			double coefficient = 1.0;
			this.AddDBGRow(this.dbgHall, this.tbNewName.Text, coefficient, false);
			this.tbNewName.Text = "";
		}

		private void InsertDBGRow(DataGridView dataGridView, string name, double coefficient, bool isBalcony)
		{
			DataGridViewRow dataGridViewRow = new DataGridViewRow();
			DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell.Value = name;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
			DataGridViewTextBoxCell dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell2.Value = coefficient;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell2);
			if (dataGridView.ColumnCount == 3)
			{
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dataGridViewCheckBoxCell.Value = isBalcony;
				dataGridViewRow.Cells.Add(dataGridViewCheckBoxCell);
			}
			dataGridView.Rows.Insert(0, dataGridViewRow);
			dataGridView.Rows[0].Selected = true;
			dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0];
		}

		private void AddDBGRow(DataGridView dataGridView, string name, double coefficient, bool isBalcony)
		{
			DataGridViewRow dataGridViewRow = new DataGridViewRow();
			DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell.Value = name;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
			DataGridViewTextBoxCell dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell2.Value = coefficient;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell2);
			if (dataGridView.ColumnCount == 3)
			{
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dataGridViewCheckBoxCell.Value = isBalcony;
				dataGridViewRow.Cells.Add(dataGridViewCheckBoxCell);
			}
			dataGridView.Rows.Add(dataGridViewRow);
		}

		private void btnDelete_Click(object sender, EventArgs e)
		{
			if (this.dbgHall.Rows.Count == 1)
			{
				return;
			}
			int index = this.dbgHall.SelectedRows[0].Index;
			this.dbgHall.Rows.RemoveAt(index);
			if (index == 0)
			{
				this.dbgHall.Rows[0].Selected = true;
			}
			else
			{
				this.dbgHall.Rows[index - 1].Selected = true;
			}
			this.tbZDName.Text = this.dbgHall.SelectedRows[0].Cells[0].Value.ToString();
			this.tbZACoefficient.Text = this.dbgHall.SelectedRows[0].Cells[1].Value.ToString();
		}

		private void dbgHall_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
		}

		private void DGVTextBoxTextChanged(object sender, EventArgs e)
		{
			string text = ((System.Windows.Forms.TextBox)sender).Text;
			double num = 0.0;
			if (!this.ValidatingDouble(text, ref num))
			{
				((System.Windows.Forms.TextBox)sender).Text = "1.0";
			}
			this.Refresh();
		}

		private bool ValidatingDouble(string strValue, ref double dValue)
		{
			double num = 0.0;
			try
			{
				num = Convert.ToDouble(strValue);
			}
			catch (Exception)
			{
				return false;
			}
			if (Geometry.Greaterthan_Or_Equal(num, 0.0) && Geometry.Lessthan_Or_Equal(num, 1.0))
			{
				dValue = num;
				return true;
			}
			YJKMessageBox.Show("数值范围：0.0～1.0");
			return false;
		}

		private void dbgHall_CurrentCellDirtyStateChanged(object sender, EventArgs e)
		{
			this.dbgHall.CommitEdit(DataGridViewDataErrorContexts.Commit);
		}

		private void dbgHall_MouseDown(object sender, MouseEventArgs e)
		{
		}

		private void dbgHall_MouseUp(object sender, MouseEventArgs e)
		{
			DataGridViewRow dataGridViewRow = this.dbgHall.SelectedRows[0];
			this.tbZDName.Text = dataGridViewRow.Cells[0].Value.ToString();
			this.tbZACoefficient.Text = dataGridViewRow.Cells[1].Value.ToString();
			this.tbZDName.Focus();
			this.tbZDName.SelectAll();
			this.UpdatePopulationDensity();
		}

		private void tbZDName_TextChanged(object sender, EventArgs e)
		{
			if (this.dbgHall.RowCount > 0)
			{
				this.dbgHall.SelectedRows[0].Cells[0].Value = this.tbZDName.Text;
				this.UpdatePopulationDensity();
			}
		}

		private void tbZACoefficient_TextChanged(object sender, EventArgs e)
		{
			if (this.dbgHall.RowCount > 0)
			{
				this.dbgHall.SelectedRows[0].Cells[1].Value = this.tbZACoefficient.Text;
			}
		}

		private void btnSet_Click(object sender, EventArgs e)
		{
			DlgRoomNumberSettings dlgRoomNumberSettings;
			if (this.bnForShareParameter.sEngName == "")
			{
				dlgRoomNumberSettings = new DlgRoomNumberSettings(this.m_Revit, false);
			}
			else
			{
				dlgRoomNumberSettings = new DlgRoomNumberSettings(this.m_Revit, true);
			}
			dlgRoomNumberSettings.ShowDialog();
		}

		private void UpdatePopulationDensity()
		{
			string text = "";
			string text2 = "";
			if (this.tabControl1.SelectedIndex == 0)
			{
				return;
			}
			if (this.tabControl1.SelectedIndex == 1)
			{
				ButtonNode buttonNode = this.arBNOffice.ElementAt(this.nOfficeIndex);
				this.UpdateDensityText("办公", this.GetChineseRoomName(buttonNode.sDName), ref text, ref text2);
				if (this.cmbODensity.SelectedIndex == 0)
				{
					this.txtOPDensity.Text = text;
					return;
				}
				this.txtOPDensity.Text = text2;
				return;
			}
			else if (this.tabControl1.SelectedIndex == 2)
			{
				ButtonNode buttonNode2 = this.arBNBusiness.ElementAt(this.nBusinessIndex);
				this.UpdateDensityText("商业", this.GetChineseRoomName(buttonNode2.sDName), ref text, ref text2);
				if (this.cmbBDensity.SelectedIndex == 0)
				{
					this.txtBPDensity.Text = text;
					return;
				}
				this.txtBPDensity.Text = text2;
				return;
			}
			else
			{
				if (this.tabControl1.SelectedIndex != 3)
				{
					if (this.tabControl1.SelectedIndex == 4)
					{
						string text3 = this.dbgHall.SelectedRows[0].Cells[0].Value.ToString();
						if (this.m_aryNameSchool.Contains(text3))
						{
							this.UpdateDensityText(text3, text3, ref text, ref text2);
						}
						else
						{
							this.UpdateDensityText("其他", text3, ref text, ref text2);
						}
						if (this.cmbOtherDensity.SelectedIndex == 0)
						{
							this.txtOtherPDensity.Text = text;
							return;
						}
						this.txtOtherPDensity.Text = text2;
					}
					return;
				}
				ButtonNode buttonNode3 = this.arBNCatering.ElementAt(this.nCateringIndex);
				this.UpdateDensityText("餐饮", this.GetChineseRoomName(buttonNode3.sDName), ref text, ref text2);
				if (this.cmbCDensity.SelectedIndex == 0)
				{
					this.txtCPDensity.Text = text;
					return;
				}
				this.txtCPDensity.Text = text2;
				return;
			}
		}

		private void UpdateDensityText(string strBuilding, string strRoomName, ref string strPM, ref string strMP)
		{
			foreach (DlgRoomNumber.PopulationDensity populationDensity in this.m_lstPopuDensity)
			{
				if (populationDensity.BuildName == strBuilding && populationDensity.LstRoomName.Contains(strRoomName))
				{
					int num = this.m_lstLevelId.IndexOf(this.m_Revit.Application.ActiveUIDocument.ActiveView.GenLevel.Id);
					num = num - this.m_n1stFloorIndex + 1;
					if (num <= -2)
					{
						strPM = populationDensity.LstPMDensity[0];
						strMP = populationDensity.LstMPDensity[0];
						break;
					}
					if (num == -1)
					{
						strPM = populationDensity.LstPMDensity[1];
						strMP = populationDensity.LstMPDensity[1];
						break;
					}
					if (num == 1 || num == 2)
					{
						strPM = populationDensity.LstPMDensity[2];
						strMP = populationDensity.LstMPDensity[2];
						break;
					}
					if (num == 3)
					{
						strPM = populationDensity.LstPMDensity[3];
						strMP = populationDensity.LstMPDensity[3];
						break;
					}
					strPM = populationDensity.LstPMDensity[4];
					strMP = populationDensity.LstMPDensity[4];
					break;
				}
			}
		}

		private void InitialDensityData()
		{
			string filename = Product.DataLocation + "\\PopulationDensity.xml";
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(filename);
			XmlNode xmlNode = xmlDocument.SelectSingleNode("PopulationDensity");
			if (xmlNode == null)
			{
				return;
			}
			XmlNodeList xmlNodeList = xmlNode.SelectNodes("Building");
			if (xmlNodeList == null)
			{
				return;
			}
			foreach (object obj in xmlNodeList)
			{
				XmlNode xmlNode2 = (XmlNode)obj;
				if (xmlNode2 != null)
				{
					XmlElement xmlElement = xmlNode2 as XmlElement;
					foreach (object obj2 in xmlNode2.SelectNodes("Room"))
					{
						XmlNode xmlNode3 = (XmlNode)obj2;
						if (xmlNode3 != null)
						{
							XmlElement elemRoom = xmlNode3 as XmlElement;
							List<string> roomNameList = this.GetRoomNameList(elemRoom);
							List<string> list = new List<string>();
							List<string> list2 = new List<string>();
							this.GetDensityValue(xmlNode3, list, list2);
							string attribute = xmlElement.GetAttribute("Name");
							DlgRoomNumber.PopulationDensity item = new DlgRoomNumber.PopulationDensity(attribute, roomNameList, list, list2);
							this.m_lstPopuDensity.Add(item);
						}
					}
				}
			}
		}

		private List<string> GetRoomNameList(XmlElement elemRoom)
		{
			List<string> list = new List<string>();
			foreach (string item in elemRoom.GetAttribute("Name").Split(new char[]
			{
				';'
			}))
			{
				list.Add(item);
			}
			return list;
		}

		private void GetDensityValue(XmlNode nodeRoom, List<string> lstValuePM, List<string> lstValueMP)
		{
			XmlNodeList xmlNodeList = nodeRoom.SelectNodes("Floor");
			if (xmlNodeList.Count <= 0)
			{
				XmlElement xmlElement = nodeRoom as XmlElement;
				string attribute = xmlElement.GetAttribute("ValuePM");
				string attribute2 = xmlElement.GetAttribute("ValueMP");
				for (int i = 0; i < 5; i++)
				{
					lstValuePM.Add(attribute);
					lstValueMP.Add(attribute2);
				}
				return;
			}
			foreach (object obj in xmlNodeList)
			{
				XmlElement xmlElement2 = ((XmlNode)obj) as XmlElement;
				string attribute3 = xmlElement2.GetAttribute("ValuePM");
				string attribute4 = xmlElement2.GetAttribute("ValueMP");
				lstValuePM.Add(attribute3);
				lstValueMP.Add(attribute4);
			}
		}

		private void GetSortFloorLevel()
		{
			List<Level> list = new List<Level>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document);
			filteredElementCollector.OfClass(typeof(Level));
			foreach (Element element in filteredElementCollector)
			{
				Level level = (Level)element;
				Parameter parameter = level.GetParameter(BuiltInParameter.LEVEL_IS_BUILDING_STORY);
				if (parameter != null && parameter.AsInteger() == 1)
				{
					list.Add(level);
				}
			}
			list.Sort((Level level1, Level level2) => level1.Elevation.CompareTo(level2.Elevation));
			double num = double.MaxValue;
			for (int i = 0; i < list.Count; i++)
			{
				this.m_lstLevelId.Add(list[i].Id);
				if (Math.Abs(list[i].Elevation - 0.0) < num)
				{
					this.m_n1stFloorIndex = i;
					num = Math.Abs(list[i].Elevation - 0.0);
				}
			}
		}

		private void cmbODensity_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.UpdatePopulationDensity();
		}

		private void cmbBDensity_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.UpdatePopulationDensity();
		}

		private void cmbCDensity_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.UpdatePopulationDensity();
		}

		private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.UpdatePopulationDensity();
		}

		private string GetChineseRoomName(string strRoomName)
		{
			int num = strRoomName.IndexOf(";");
			if (num == -1)
			{
				num = strRoomName.IndexOf("；");
			}
			if (num > 0)
			{
				return strRoomName.Substring(0, num);
			}
			if (num == -1)
			{
				return strRoomName;
			}
			return "";
		}

		private string GetEnglishRoomName(string strRoomName)
		{
			int num = strRoomName.IndexOf(";");
			if (num == -1)
			{
				num = strRoomName.IndexOf("；");
			}
			if (num > 0)
			{
				return strRoomName.Substring(num + 1);
			}
			return "";
		}

		private void txtOPDensity_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtBPDensity_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtCPDensity_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtOtherPDensity_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private string GetPopulationDensity()
		{
			string text = "";
			if (this.tabControl1.SelectedIndex == 0)
			{
				return "";
			}
			if (this.tabControl1.SelectedIndex == 1)
			{
				text = this.txtOPDensity.Text;
				if (this.cmbODensity.SelectedIndex == 1)
				{
					text = (1.0 / Convert.ToDouble(text)).ToString("0.00");
				}
			}
			else if (this.tabControl1.SelectedIndex == 2)
			{
				text = this.txtBPDensity.Text;
				if (this.cmbBDensity.SelectedIndex == 1)
				{
					text = (1.0 / Convert.ToDouble(text)).ToString("0.00");
				}
			}
			else if (this.tabControl1.SelectedIndex == 3)
			{
				text = this.txtCPDensity.Text;
				if (this.cmbCDensity.SelectedIndex == 1)
				{
					text = (1.0 / Convert.ToDouble(text)).ToString("0.00");
				}
			}
			else if (this.tabControl1.SelectedIndex == 4)
			{
				text = this.txtOtherPDensity.Text;
				if (this.cmbOtherDensity.SelectedIndex == 1)
				{
					text = (1.0 / Convert.ToDouble(text)).ToString("0.00");
				}
			}
			return text;
		}

		private ExternalCommandData m_Revit;

		public ButtonNode bnForShareParameter;

		private string RootNodeName = "RoomNumberData";

		private string ResidenceNodeName = "ResidenceData";

		private string OfficeNodeName = "OfficeData";

		private string BusinessNodeName = "BusinessData";

		private string CateringNodeName = "CateringData";

		private string CustomNodeName = "CustomData";

		private bool bCreatedResidence;

		private bool bCreatedOffice;

		private bool bCreatedBusiness;

		private bool bCreatedCatering;

		private bool bCreatedCustom;

		private RadioButton btnSelectedResidence;

		private RadioButton btnSelectedOffice;

		private RadioButton btnSelectedBusiness;

		private RadioButton btnSelectedCatering;

		private int nResidenceIndex;

		private int nOfficeIndex;

		private int nBusinessIndex;

		private int nCateringIndex;

		private List<ButtonNode> arBNResidence = new List<ButtonNode>();

		private List<ButtonNode> arBNOffice = new List<ButtonNode>();

		private List<ButtonNode> arBNBusiness = new List<ButtonNode>();

		private List<ButtonNode> arBNCatering = new List<ButtonNode>();

		private List<ButtonNode> arBNCustom = new List<ButtonNode>();

		private DlgRoomNumber.OperateType m_CurrentOperateType = DlgRoomNumber.OperateType.OT_Pick;

		private bool m_PickButton;

		private List<DlgRoomNumber.PopulationDensity> m_lstPopuDensity = new List<DlgRoomNumber.PopulationDensity>();

		private List<ElementId> m_lstLevelId = new List<ElementId>();

		private int m_n1stFloorIndex;

		private string[] m_aryNameSchool = new string[]
		{
			"小学",
			"中学",
			"幼儿及中等师范",
			"合班教室",
			"教师办公室"
		};

		public const int USER = 1280;

		public const int WM_MYMESSAGE = 1281;

		public enum OperateType
		{
			OT_Pick = 1,
			OT_Continue,
			OT_Change
		}

		private struct PopulationDensity
		{
			public string BuildName
			{
				get
				{
					return this.m_BuildingName;
				}
				set
				{
					this.m_BuildingName = value;
				}
			}

			public List<string> LstRoomName
			{
				get
				{
					return this.m_lstRoomName;
				}
				set
				{
					this.m_lstRoomName = value;
				}
			}

			public List<string> LstPMDensity
			{
				get
				{
					return this.m_lstPMDensity;
				}
				set
				{
					this.m_lstPMDensity = value;
				}
			}

			public List<string> LstMPDensity
			{
				get
				{
					return this.m_lstMPDensity;
				}
				set
				{
					this.m_lstMPDensity = value;
				}
			}

			public PopulationDensity(string strBuildingName, List<string> lstRoomName, List<string> lstPMDensity, List<string> lstMPDensity)
			{
				this.m_BuildingName = strBuildingName;
				this.m_lstRoomName = lstRoomName;
				this.m_lstPMDensity = lstPMDensity;
				this.m_lstMPDensity = lstMPDensity;
			}

			private string m_BuildingName;

			private List<string> m_lstRoomName;

			private List<string> m_lstPMDensity;

			private List<string> m_lstMPDensity;
		}
	}
}
